package com.m5;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * Created by 名字 on 2021/7/27.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class B{
    private  String name;
    private  int age;

    public static void main(String[] args) {

        ArrayList<B> bs = new ArrayList<B>();
        bs.add(new B("xiao",1));
        bs.add(new B("xiao",8));
        bs.add(new B("xiao",2));
        bs.add(new B("xiao",5));
        bs.add(new B("xiao",6));
        bs.add(new B("xiao",7));
        bs.add(new B("xiao",3));
        Collections.sort(bs, new Comparator<B>() {
            @Override
            public int compare(B o1, B o2) {
                if(o1.age!=o2.age){
                    return o1.age-o2.age;
                }else{
                    return o1.getName().compareTo(o2.getName());
                }
            }
        });
        for (B b : bs) {
            System.out.println(b.name+b.age);
        }
    }
}
